﻿Imports TMySQL
Public Class frmSQLCapture
    Implements ITabForm
    Private Const INFO_COLUMN As Integer = 8
    Private _MyQuery As New TMyQuery
    Public Sub New()
        ' この呼び出しは、Windows フォーム デザイナで必要です。
        InitializeComponent()
        ' InitializeComponent() 呼び出しの後で初期化を追加します。
        _MyQuery.Session = frmMain.Connection
        InitFrm()
    End Sub
    Private Sub InitFrm()
        frmMain.GridSettings.ApplyAll(Me)
        frmMain.GeneralSettings.ApplyAll(Me)
        frmMain.EditorSettings.ApplyAll(Me)
    End Sub

    Private Sub cmdRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRefresh.Click
        If Not frmMain.CaptureProcessList.Captured Then
            If MsgBox("SQL監視が実行されていません。" & vbNewLine & "監視を開始しますか?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
                frmMain.mnuSetSQLCapture.Checked = True
            End If
        End If
        frmMain.CaptureProcessList.GetHistory()
        Grid.DataSource = frmMain.CaptureProcessList.DataTable
    End Sub

    Private Sub Grid_CellEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Grid.CellEnter

        Cursor.Current = Cursors.WaitCursor
        Try
            Dim sql As String = Grid.Item(INFO_COLUMN, e.RowIndex).Value.ToString
            pnl.Controls.Clear()
            pnl.SuspendLayout()
            Dim frmRet As New frmExplain
            Try
                frmRet.TopLevel = False
                frmRet.Parent = pnl
                frmRet.Dock = DockStyle.Fill
                frmRet.SQL = sql
                frmRet.Show()
            Catch ex As Exception
                frmRet.Dispose()
            Finally
                pnl.ResumeLayout()
            End Try
        Finally
            Cursor.Current = Cursors.Default
        End Try
    End Sub
End Class